<script>
export default {
  props: {
    size: {
      type: String,
      default: "medium", // small, medium, large
    },
    color: {
      type: String,
      default: "#ff9800",
    },
    text: {
      type: String,
      default: "加载中...",
    },
    fullScreen: {
      type: Boolean,
      default: false,
    },
  },
};
</script>

<template>
  <div class="loading-container" :class="{ 'full-screen': fullScreen }">
    <div class="spinner" :class="size">
      <svg viewBox="0 0 50 50" :style="{ color: color }">
        <circle
          class="path"
          cx="25"
          cy="25"
          r="20"
          fill="none"
          stroke-width="5"
        ></circle>
      </svg>
    </div>
    <div v-if="text" class="loading-text">{{ text }}</div>
  </div>
</template>

<style scoped>
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.full-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.8);
  z-index: 9999;
}

.spinner {
  animation: rotate 2s linear infinite;
  z-index: 2;
  width: 30px;
  height: 30px;
}

.spinner.small {
  width: 20px;
  height: 20px;
}

.spinner.medium {
  width: 30px;
  height: 30px;
}

.spinner.large {
  width: 50px;
  height: 50px;
}

.spinner .path {
  stroke: currentColor;
  stroke-linecap: round;
  animation: dash 1.5s ease-in-out infinite;
}

.loading-text {
  margin-top: 0.5rem;
  font-size: 14px;
  color: #666;
}

@keyframes rotate {
  100% {
    transform: rotate(360deg);
  }
}

@keyframes dash {
  0% {
    stroke-dasharray: 1, 150;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -35;
  }
  100% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -124;
  }
}
</style>
